<?php

namespace App\Services;

use App\Models\Catalog;

class CatalogService extends BaseService {


    public function getL1List()
    {
        return Catalog::query()->where('level','=','L1')->first();
    }

    public function getL1ById($id)
    {
        return Catalog::query()->where('level','=','L1')
            ->where('id','=',$id)->first();
    }

    public function getL2ListByPid(int $pid)
    {
        return Catalog::query()->where('level','=','L2')
            ->where('pid','=',$pid)
            ->get();
    }

    public function getById($id)
    {
        return Catalog::query()->find($id);
    }

    public function getL2ListByIds($ids)
    {
        if (empty($ids)) {
            return collect([]);
        }
        return Catalog::query()->whereIn('id',$ids)
            ->where('level','=','L2')
            ->get();
    }
}
